// pages/shop/shop.js
var app = getApp();
Page({
  data:{

  },
  onLoad:function(){

  },
  onReady: function(){
    var that = this;
    app.func.req('shops/orders_info', {}, 'GET', function(res){
      console.log(res)
      that.setData({
        ordersInfo: res.result
      });
    },{
      'token': wx.getStorageSync('token')
    });
  },
  onShow: function(){
    var that = this;
    app.func.req('shops/show', {
      id: wx.getStorageSync('shop').id
    }, 'GET', function(res){
      that.setData({
        shop: res.result
      });
    },{
      'token': wx.getStorageSync('token')
    });
  },
  goHome:function(){
    // wx.removeStorageSync('shop');
    var url = wx.getStorageSync('current_index_url');
    if (!url || url.length<1) {
      url = '../load/load';
    }
    wx.reLaunch({
      url: url
    });
  },
  logout:function(){
    var url = wx.getStorageSync('current_index_url');
    if (!url || url.length < 1) {
      url = '../load/load';
    }
    wx.removeStorageSync('shop');
    wx.removeStorageSync('current_index_url');
    wx.removeStorageSync('indexType');
    wx.reLaunch({
      url: url
    });
  },
  onPullDownRefresh: function(){
    var that = this;
    app.func.req('shops/orders_info', {}, 'GET', function (res) {
      that.setData({
        ordersInfo: res.result
      });
      app.func.req('shops/show', {
        id: wx.getStorageSync('shop').id
      }, 'GET', function (res) {
        that.setData({
          shop: res.result
        });
        wx.stopPullDownRefresh()
      }, {
          'token': wx.getStorageSync('token')
        });
    }, {
        'token': wx.getStorageSync('token')
      });
  },
  showTips: function(){
    wx.showModal({
      title: '提示',
      content: '下拉可刷新统计数据，数据不包括未支付、已取消、已退款的订单',
      showCancel: false,
      confirmText: '朕知道了',
    })
  }
})
